package com.example.demo.pattern.iterator;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenchao
 * @date 2021/11/8
 */
public class WithoutIteratorPattern {

    public static void main(String[] args) {
        Student student1 =new Student("张三");
        Student student2 =new Student("李四");
        Map<String, Student> students = new HashMap<String, Student>();
        students.put(student1.getName(), student1);
        students.put(student2.getName(), student2);
        Classroom classroom = new Classroom();
        classroom.setStudents(students);
        Map<String, Student> resultStudents = classroom.getStudents();
        for(Student resultStudent : resultStudents.values()) {
            System.out.println(resultStudent);
        }

    }

    /**
     * 教室类
     * @author chenchao
     *
     */
    public static class Classroom {

        private Map<String, Student> students;

        public Map<String, Student> getStudents() {
            return students;
        }

        public void setStudents(Map<String, Student> students) {
            this.students = students;
        }

    }
    /**
     * 学生类
     * @author chenchao
     *
     */
    public static class Student {
        private  String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Student(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    '}';
        }
    }
}
